<?php

/**
 * ListOffersRequestFilters.
 *
 * PHP version 8.3
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */

/**
 * Selling Partner API for Replenishment.
 *
 * The Selling Partner API for Replenishment (Replenishment API) provides programmatic access to replenishment program metrics and offers. These programs provide recurring delivery of any replenishable item at a frequency chosen by the customer.  The Replenishment API is available worldwide wherever Amazon Subscribe & Save is available or is supported. The API is available to vendors and FBA selling partners.
 *
 * The version of the OpenAPI document: 2022-11-07
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.9.0
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

namespace SpApi\Model\replenishment\v2022_11_07;

use SpApi\Model\ModelInterface;
use SpApi\ObjectSerializer;

/**
 * ListOffersRequestFilters Class Doc Comment.
 *
 * @category Class
 *
 * @description Use these parameters to filter results. Any result must match all of the provided parameters. For any parameter that is an array, the result must match at least one element in the provided array.
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 *
 * @implements \ArrayAccess<string, mixed>
 */
class ListOffersRequestFilters implements ModelInterface, \ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

    /**
     * The original name of the model.
     */
    protected static string $openAPIModelName = 'ListOffersRequestFilters';

    /**
     * Array of property to type mappings. Used for (de)serialization.
     *
     * @var string[]
     */
    protected static array $openAPITypes = [
        'marketplace_id' => 'string',
        'skus' => 'string[]',
        'asins' => 'string[]',
        'eligibilities' => '\SpApi\Model\replenishment\v2022_11_07\EligibilityStatus[]',
        'preferences' => '\SpApi\Model\replenishment\v2022_11_07\Preference',
        'promotions' => '\SpApi\Model\replenishment\v2022_11_07\Promotion',
        'program_types' => '\SpApi\Model\replenishment\v2022_11_07\ProgramType[]'];

    /**
     * Array of property to format mappings. Used for (de)serialization.
     *
     * @var string[]
     *
     * @phpstan-var array<string, string|null>
     *
     * @psalm-var array<string, string|null>
     */
    protected static array $openAPIFormats = [
        'marketplace_id' => null,
        'skus' => null,
        'asins' => null,
        'eligibilities' => null,
        'preferences' => null,
        'promotions' => null,
        'program_types' => null];

    /**
     * Array of nullable properties. Used for (de)serialization.
     *
     * @var bool[]
     */
    protected static array $openAPINullables = [
        'marketplace_id' => false,
        'skus' => true,
        'asins' => true,
        'eligibilities' => true,
        'preferences' => true,
        'promotions' => true,
        'program_types' => false,
    ];

    /**
     * If a nullable field gets set to null, insert it here.
     *
     * @var bool[]
     */
    protected array $openAPINullablesSetToNull = [];

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     *
     * @var string[]
     */
    protected static array $attributeMap = [
        'marketplace_id' => 'marketplaceId',
        'skus' => 'skus',
        'asins' => 'asins',
        'eligibilities' => 'eligibilities',
        'preferences' => 'preferences',
        'promotions' => 'promotions',
        'program_types' => 'programTypes',
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     *
     * @var string[]
     */
    protected static array $setters = [
        'marketplace_id' => 'setMarketplaceId',
        'skus' => 'setSkus',
        'asins' => 'setAsins',
        'eligibilities' => 'setEligibilities',
        'preferences' => 'setPreferences',
        'promotions' => 'setPromotions',
        'program_types' => 'setProgramTypes',
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests).
     *
     * @var string[]
     */
    protected static array $getters = [
        'marketplace_id' => 'getMarketplaceId',
        'skus' => 'getSkus',
        'asins' => 'getAsins',
        'eligibilities' => 'getEligibilities',
        'preferences' => 'getPreferences',
        'promotions' => 'getPromotions',
        'program_types' => 'getProgramTypes',
    ];

    /**
     * Associative array for storing property values.
     */
    protected array $container = [];

    /**
     * Constructor.
     *
     * @param null|array $data Associated array of property values
     *                         initializing the model
     */
    public function __construct(?array $data = null)
    {
        $this->setIfExists('marketplace_id', $data ?? [], null);
        $this->setIfExists('skus', $data ?? [], null);
        $this->setIfExists('asins', $data ?? [], null);
        $this->setIfExists('eligibilities', $data ?? [], null);
        $this->setIfExists('preferences', $data ?? [], null);
        $this->setIfExists('promotions', $data ?? [], null);
        $this->setIfExists('program_types', $data ?? [], null);
    }

    /**
     * Gets the string presentation of the object.
     *
     * @return string
     */
    public function __toString()
    {
        return json_encode(
            ObjectSerializer::sanitizeForSerialization($this),
            JSON_PRETTY_PRINT
        );
    }

    /**
     * Array of property to type mappings. Used for (de)serialization.
     */
    public static function openAPITypes(): array
    {
        return self::$openAPITypes;
    }

    /**
     * Array of property to format mappings. Used for (de)serialization.
     */
    public static function openAPIFormats(): array
    {
        return self::$openAPIFormats;
    }

    /**
     * Checks if a property is nullable.
     */
    public static function isNullable(string $property): bool
    {
        return self::openAPINullables()[$property] ?? false;
    }

    /**
     * Checks if a nullable property is set to null.
     */
    public function isNullableSetToNull(string $property): bool
    {
        return in_array($property, $this->getOpenAPINullablesSetToNull(), true);
    }

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     */
    public static function attributeMap(): array
    {
        return self::$attributeMap;
    }

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     */
    public static function setters(): array
    {
        return self::$setters;
    }

    /**
     * Array of attributes to getter functions (for serialization of requests).
     */
    public static function getters(): array
    {
        return self::$getters;
    }

    /**
     * The original name of the model.
     */
    public function getModelName(): string
    {
        return self::$openAPIModelName;
    }

    /**
     * Show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     */
    public function listInvalidProperties(): array
    {
        $invalidProperties = [];

        if (null === $this->container['marketplace_id']) {
            $invalidProperties[] = "'marketplace_id' can't be null";
        }
        if (!is_null($this->container['skus']) && (count($this->container['skus']) > 20)) {
            $invalidProperties[] = "invalid value for 'skus', number of items must be less than or equal to 20.";
        }

        if (!is_null($this->container['skus']) && (count($this->container['skus']) < 1)) {
            $invalidProperties[] = "invalid value for 'skus', number of items must be greater than or equal to 1.";
        }

        if (!is_null($this->container['asins']) && (count($this->container['asins']) > 20)) {
            $invalidProperties[] = "invalid value for 'asins', number of items must be less than or equal to 20.";
        }

        if (!is_null($this->container['asins']) && (count($this->container['asins']) < 1)) {
            $invalidProperties[] = "invalid value for 'asins', number of items must be greater than or equal to 1.";
        }

        if (!is_null($this->container['eligibilities']) && (count($this->container['eligibilities']) < 1)) {
            $invalidProperties[] = "invalid value for 'eligibilities', number of items must be greater than or equal to 1.";
        }

        if (null === $this->container['program_types']) {
            $invalidProperties[] = "'program_types' can't be null";
        }
        if (count($this->container['program_types']) < 1) {
            $invalidProperties[] = "invalid value for 'program_types', number of items must be greater than or equal to 1.";
        }

        return $invalidProperties;
    }

    /**
     * Validate all the properties in the model
     * return true if all passed.
     *
     * @return bool True if all properties are valid
     */
    public function valid(): bool
    {
        return 0 === count($this->listInvalidProperties());
    }

    /**
     * Gets marketplace_id.
     */
    public function getMarketplaceId(): string
    {
        return $this->container['marketplace_id'];
    }

    /**
     * Sets marketplace_id.
     *
     * @param string $marketplace_id The marketplace identifier. The supported marketplaces for both sellers and vendors are US, CA, ES, UK, FR, IT, IN, DE and JP. The supported marketplaces for vendors only are BR, AU, MX, AE and NL. Refer to [Marketplace IDs](https://developer-docs.amazon.com/sp-api/docs/marketplace-ids) to find the identifier for the marketplace.
     */
    public function setMarketplaceId(string $marketplace_id): self
    {
        if (is_null($marketplace_id)) {
            throw new \InvalidArgumentException('non-nullable marketplace_id cannot be null');
        }
        $this->container['marketplace_id'] = $marketplace_id;

        return $this;
    }

    /**
     * Gets skus.
     */
    public function getSkus(): ?array
    {
        return $this->container['skus'];
    }

    /**
     * Sets skus.
     *
     * @param null|array $skus A list of SKUs to filter. This filter is only supported for sellers and not for vendors.
     */
    public function setSkus(?array $skus): self
    {
        if (is_null($skus)) {
            array_push($this->openAPINullablesSetToNull, 'skus');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('skus', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }

        if (!is_null($skus) && (count($skus) > 20)) {
            throw new \InvalidArgumentException('invalid value for $skus when calling ListOffersRequestFilters., number of items must be less than or equal to 20.');
        }
        if (!is_null($skus) && (count($skus) < 1)) {
            throw new \InvalidArgumentException('invalid length for $skus when calling ListOffersRequestFilters., number of items must be greater than or equal to 1.');
        }
        $this->container['skus'] = $skus;

        return $this;
    }

    /**
     * Gets asins.
     */
    public function getAsins(): ?array
    {
        return $this->container['asins'];
    }

    /**
     * Sets asins.
     *
     * @param null|array $asins a list of Amazon Standard Identification Numbers (ASINs)
     */
    public function setAsins(?array $asins): self
    {
        if (is_null($asins)) {
            array_push($this->openAPINullablesSetToNull, 'asins');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('asins', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }

        if (!is_null($asins) && (count($asins) > 20)) {
            throw new \InvalidArgumentException('invalid value for $asins when calling ListOffersRequestFilters., number of items must be less than or equal to 20.');
        }
        if (!is_null($asins) && (count($asins) < 1)) {
            throw new \InvalidArgumentException('invalid length for $asins when calling ListOffersRequestFilters., number of items must be greater than or equal to 1.');
        }
        $this->container['asins'] = $asins;

        return $this;
    }

    /**
     * Gets eligibilities.
     */
    public function getEligibilities(): ?array
    {
        return $this->container['eligibilities'];
    }

    /**
     * Sets eligibilities.
     *
     * @param null|array $eligibilities a list of eligibilities associated with an offer
     */
    public function setEligibilities(?array $eligibilities): self
    {
        if (is_null($eligibilities)) {
            array_push($this->openAPINullablesSetToNull, 'eligibilities');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('eligibilities', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }

        if (!is_null($eligibilities) && (count($eligibilities) < 1)) {
            throw new \InvalidArgumentException('invalid length for $eligibilities when calling ListOffersRequestFilters., number of items must be greater than or equal to 1.');
        }
        $this->container['eligibilities'] = $eligibilities;

        return $this;
    }

    /**
     * Gets preferences.
     */
    public function getPreferences(): ?Preference
    {
        return $this->container['preferences'];
    }

    /**
     * Sets preferences.
     *
     * @param null|Preference $preferences preferences
     */
    public function setPreferences(?Preference $preferences): self
    {
        if (is_null($preferences)) {
            array_push($this->openAPINullablesSetToNull, 'preferences');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('preferences', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['preferences'] = $preferences;

        return $this;
    }

    /**
     * Gets promotions.
     */
    public function getPromotions(): ?Promotion
    {
        return $this->container['promotions'];
    }

    /**
     * Sets promotions.
     *
     * @param null|Promotion $promotions promotions
     */
    public function setPromotions(?Promotion $promotions): self
    {
        if (is_null($promotions)) {
            array_push($this->openAPINullablesSetToNull, 'promotions');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('promotions', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['promotions'] = $promotions;

        return $this;
    }

    /**
     * Gets program_types.
     */
    public function getProgramTypes(): array
    {
        return $this->container['program_types'];
    }

    /**
     * Sets program_types.
     *
     * @param array $program_types a list of replenishment program types
     */
    public function setProgramTypes(array $program_types): self
    {
        if (is_null($program_types)) {
            throw new \InvalidArgumentException('non-nullable program_types cannot be null');
        }

        if (count($program_types) < 1) {
            throw new \InvalidArgumentException('invalid length for $program_types when calling ListOffersRequestFilters., number of items must be greater than or equal to 1.');
        }
        $this->container['program_types'] = $program_types;

        return $this;
    }

    /**
     * Returns true if offset exists. False otherwise.
     *
     * @param int $offset Offset
     */
    public function offsetExists($offset): bool
    {
        return isset($this->container[$offset]);
    }

    /**
     * Gets offset.
     *
     * @param int $offset Offset
     *
     * @return null|mixed
     */
    #[\ReturnTypeWillChange]
    public function offsetGet($offset): mixed
    {
        return $this->container[$offset] ?? null;
    }

    /**
     * Sets value based on offset.
     *
     * @param null|int $offset Offset
     * @param mixed    $value  Value to be set
     */
    public function offsetSet($offset, mixed $value): void
    {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }

    /**
     * Unsets offset.
     *
     * @param int $offset Offset
     */
    public function offsetUnset($offset): void
    {
        unset($this->container[$offset]);
    }

    /**
     * Serializes the object to a value that can be serialized natively by json_encode().
     *
     * @see https://www.php.net/manual/en/jsonserializable.jsonserialize.php
     *
     * @return mixed returns data which can be serialized by json_encode(), which is a value
     *               of any type other than a resource
     */
    #[\ReturnTypeWillChange]
    public function jsonSerialize(): mixed
    {
        return ObjectSerializer::sanitizeForSerialization($this);
    }

    /**
     * Gets a header-safe presentation of the object.
     */
    public function toHeaderValue(): string
    {
        return json_encode(ObjectSerializer::sanitizeForSerialization($this));
    }

    /**
     * Array of nullable properties.
     */
    protected static function openAPINullables(): array
    {
        return self::$openAPINullables;
    }

    /**
     * Array of nullable field names deliberately set to null.
     *
     * @return bool[]
     */
    private function getOpenAPINullablesSetToNull(): array
    {
        return $this->openAPINullablesSetToNull;
    }

    /**
     * Setter - Array of nullable field names deliberately set to null.
     *
     * @param bool[] $openAPINullablesSetToNull
     */
    private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void
    {
        $this->openAPINullablesSetToNull = $openAPINullablesSetToNull;
    }

    /**
     * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
     * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
     * $this->openAPINullablesSetToNull array.
     *
     * @param mixed $defaultValue
     */
    private function setIfExists(string $variableName, array $fields, $defaultValue): void
    {
        if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) {
            $this->openAPINullablesSetToNull[] = $variableName;
        }

        $this->container[$variableName] = $fields[$variableName] ?? $defaultValue;
    }
}
